<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
		<title>公司往来单位维护</title>
		
		<link rel="stylesheet" type="text/css" href="../css/cm-default.css"  />
		<link rel="stylesheet" type="text/css" href="../ligerUI/skins/Aqua/css/ligerui-all.css" />
		<link rel="stylesheet" type="text/css" href="../ligerUI/skins/ligerui-icons.css" />
		<script src="../js/jquery-min.js" type="text/javascript"></script>
		<script src="../js/validate/jquery.validate.js" type="text/javascript"></script>
		<script src="../js/validate/jquery.metadata.js" type="text/javascript"></script>
		<script src="../js/validate/messages_zh.js" type="text/javascript"></script>
		<script src="../ligerUI/js/ligerui.min.js" type="text/javascript"></script>
		<script src="../js/common.js" type="text/javascript"></script>
		<script src="../js/json2.js" type="text/javascript"></script>
		<script type="text/javascript">
			var defGrid;
			var userid;
			var region,org,typeC,trade,lecel,bank;
			$(function(){
				$("#layout_main").ligerLayout({
                });

               	defGrid = $("#query_list").ligerGrid({
                    columns:[
						{display:'操作',isSort:false,width:60,render:function(rowdata,rowindex,value) {
                        	var h = "";
                        	if (!rowdata._editing) {
                                h += "<a href='javascript:void(0);' class='opt-link' onclick='beginEdit(" + rowindex + ")'>修改</a> ";
                                h += "<a href='javascript:void(0);' class='opt-link' onclick='deleteRow(" + rowindex + ")'>删除</a> "; 
                            } else {
                                h += "<a href='javascript:void(0);' class='opt-link' onclick='endEdit(" + rowindex + ")'>提交</a> ";
                                h += "<a href='javascript:void(0);' class='opt-link' onclick='cancelEdit(" + rowindex + ")'>取消</a> "; 
                            }
                            return h;
                        },frozen:true},
                        //{display:'单位类型',name:'type',width:80,minWidth:60,data:get_type_list,render:switcher_type,editor:{type:'select',data:get_type_list,textField:'name',valueField:'value',selectBoxHeight:50}},
                        {display:'编号',name:'code',width:40,minWidth:60,align:'left',editor:{type:'text'}},
	                    {display:'名称',name:'name',width:200,minWidth:60,align:'left',editor:{type:'text'}},
	                    {display:'所属机构',name:'dept_id',width:80,minWidth:60,data:get_org_list,render:switcher_org,editor:{type:'select',data:get_org_list,textField:'name',valueField:'value',selectBoxHeight:50}},
	                    {display:'所属行政区划',name:'Of_Region',width:100,minWidth:60,align:'left',render:function(item){return paramRender(item,'Of_Region',item.Of_Region);}},
	                    {display:'组织机构代码证号',name:'uuid_code',width:80,minWidth:60,align:'left',editor:{type:'text'}},
	                    {display:'税号',name:'tax_code',width:80,minWidth:60,align:'left',editor:{type:'text'}},
	                    {display:'所属行业',name:'of_trade',width:80,minWidth:60,data:get_trade_list,render:switcher_trade,editor:{type:'select',data:get_trade_list,textField:'name',valueField:'value',selectBoxHeight:50}},
	                    {display:'法人代表',name:'legal_body',width:80,minWidth:60,align:'left',editor:{type:'text'}},
	                    //{display:'信用级别',name:'credit_level',width:80,minWidth:60,data:get_level_list,render:switcher_level,editor:{type:'select',data:get_level_list,textField:'name',valueField:'value',selectBoxHeight:50}},
	                    {display:'开户行',name:'bank',width:80,minWidth:60,data:get_bank_list,render:switcher_bank,editor:{type:'select',data:get_bank_list,textField:'name',valueField:'value',selectBoxHeight:50}},
	                    {display:'银行帐号',name:'bank_account',width:80,minWidth:60,align:'left',editor:{type:'text'}},
	                    {display:'联系人',name:'link_man',width:80,minWidth:60,align:'left',editor:{type:'text'}},
	                    {display:'手机号',name:'mobile',width:50,minWidth:60,align:'left',editor:{type:'text'}},
	                    {display:'单位电话',name:'phone',width:50,minWidth:60,align:'left',editor:{type:'text'}},
	                    {display:'单位传真',name:'fax',width:50,minWidth:60,align:'left',editor:{type:'text'}},
			            {display:'说明',name:'description',width:100,align:'left',editor:{type:'text'}}
                    ],
                    pageSize:10,
                    usePager: true,
                    sortName:'id',
                    width:'100%',
                    height:'100%',
                    dataAction:'server',
                    checkbox:false,
                    rownumbers:false,
                    fixedCellHeight:false,
                    colDraggable:true,
                    enabledEdit:true,
                    clickToEdit:false,
                    onSelectRow:function(rowdata, rowindex){$("#txtrowindex").val(rowindex);},
//                     onUnSelectRow:unselected,
                    onReload: toQuery,
//                     onToFirst: toFirst,
//                     onToLast: toLast,
//                     onToNext: toNext,
//                     onToPrev: toPrev,
                     url: '../common/q.jsp',                   
                    //wws 2014-2-23 增加分页信息 start
                    onToFirst: function(item) {
                        toQuery(item, 1);
                    },
                    onToLast: function(item) {
        				var p = parseInt(defGrid.options.total / defGrid.options.pageSize);
        				if (defGrid.options.total % defGrid.options.pageSize > 0)
        					p += 1;
        				toQuery(item, p);
                    },
                    onToPrev: function(item) {
        				var p = parseInt(defGrid.options.page);
        				if (p > 1)
        					p -= 1;
        				else
            				return;
        				toQuery(item, p);
                    },
                    onToNext: function(item) {
                    	var p = parseInt(defGrid.options.total / defGrid.options.pageSize);
        				if (defGrid.options.total % defGrid.options.pageSize > 0)
        					p += 1;
    					var cp = parseInt(defGrid.options.page); 
    					if (cp < p)
        					cp += 1;
        				toQuery(item, cp);
                    },
        		    //wws 2014-2-23 增加分页信息 end 
                    param_status:'rbac.status',
                    param_org:'org_list',
                    param_type:'unit_type',
                    param_trade:'Industry',
                    param_level:'credit_rating',
                    param_bank:'bank_account',
                    param_region:'region'
				});
				defGrid.options.dataAction = 'server';
				appendAddBtn(openUserDef, "添加用户");
				$("#pageloading").hide();
			
			
				//var org_data = getData('org_list');
				region=$("#region_combobox").ligerComboBox({
					autocomplete: true,
                	valueField:'value',
                	textField:'name',
                	data:get_region_list,
                	onSelected:function(v,t) {
                    	$("#Of_Region").val(v);
                }
			   });
				org=$("#org_combobox").ligerComboBox({
					autocomplete: true,
                	valueField:'value',
                	textField:'name',
                	data:get_org_list,
                	onSelected:function(v,t) {
                    	$("#Dept_ID").val(v);
                }
			   });  
// 				typeC=$("#type_combobox").ligerComboBox({
// 					autocomplete: true,
//                 	valueField:'value',
//                 	textField:'name',
//                 	data:get_type_list,
//                 	onSelected:function(v,t) {
//                     	$("#newType").val(v);
//                 }
// 			});
				
				trade=$("#trade_combobox").ligerComboBox({
					autocomplete: true,
                	valueField:'value',
                	textField:'name',
                	data:get_trade_list,
                	onSelected:function(v,t) {
                    	$("#newOf_trade").val(v);
                }
			});
// 				lecel=$("#lecel_combobox").ligerComboBox({
// 					autocomplete: true,
//                 	valueField:'value',
//                 	textField:'name',
//                 	data:get_level_list,
//                 	onSelected:function(v,t) {
//                     	$("#newCredit_level").val(v);
//                 }
// 			});

				bank=$("#bank_combobox").ligerComboBox({
					autocomplete: true,
                	valueField:'value',
                	textField:'name',
                	data:get_bank_list,
                	onSelected:function(v,t) {
                    	$("#newBank").val(v);
                }
			});
				//默认查询全部数据 
				toQuery();
			});
	        function beginEdit(rowid) { 
	        	defGrid.beginEdit(rowid);
	        }
	        function cancelEdit(rowid) { 
	        	defGrid.cancelEdit(rowid);
	        }
	        function endEdit(rowid) {
	            defGrid.endEdit(rowid);
	            var row = defGrid.getRow(rowid);
	            toModify(JSON.stringify(row));
	        }
	        function deleteRow(rowid) {
	            $.ligerDialog.confirm('您确定要删除该项数据吗？', function(r) {
		            if (!r)
			            return;
	                var row = defGrid.getRow(rowid);
	                if (row['__status'] !== 'add')
	                	toDel(JSON.stringify(row));
	                defGrid.deleteRow(rowid);
	            })
	        }
			function switcher(item) {
				return paramRender(item, defGrid.options.param_status, item.status);
			}
			var getStatus = new function () {
				return getData('rbac.status');
			}
			function switcher_org(item) {
				return paramRender(item, defGrid.options.param_org, item.dept_id);
			}
			var get_org_list=new function () {
				return getData('org_list');
			}
			var get_region_list=new function () {
				return getData('region');
			}
			function switcher_type(item) {
				return paramRender(item, defGrid.options.param_type, item.type);
			}
			var get_type_list=new function () {
				return getData('unit_type');
			}

			function switcher_trade(item) {
				return paramRender(item, defGrid.options.param_trade, item.of_trade);
			}
			var get_trade_list=new function () {
				return getData('Industry');
			}

			function switcher_level(item) {
				return paramRender(item, defGrid.options.param_level, item.credit_level);
			}
			var get_level_list=new function () {
				return getData('credit_rating');
			}

			function switcher_bank(item) {
				return paramRender(item, defGrid.options.param_bank, item.bank);
			}
			var get_bank_list=new function () {
				return getData('bank_account');
			}
			function toQuery(item, page, pageSize) {
				if (!page)
					page = defGrid.options.page;
				if (!pageSize)
					pageSize = defGrid.options.pageSize;
				
				var param = new Object();
			    param.account=$("#AccountCode").val();
				param.name = $("#userName").val();
				//param.code = $("#dictCode").val();
				param.status = $("#dictStatus").val();
				var data = JSON.stringify(reqObj('q','rbac.select.dict.def.queryPartner',JSON.stringify(param),'l',true,page,pageSize));
				ajaxSubmit("/cmwifi/rbac/cm.do?m=q", data, function(data) {
                    //wws 2014-2-23 增加分页信息 start 
					var d = data['data'].Rows;
					var ps = defGrid.options.pageSize, p = defGrid.options.page, t = parseInt(data['data'].Total);
					if (t > ps) {
						for (var i = 0; i < (p - 1) * ps; i++) {
							d.unshift(null);
						}
					}
					defGrid.data = data['data'];
					 //wws 2014-2-23 增加分页信息  end 
					defGrid.set({data: data['data']});
				});
			}
			function toFirst() {
				toQuery(null, 1);
			}
			function toLast() {
				var p = parseInt(defGrid.options.total / defGrid.options.pageSize);
				if (defGrid.options.total % defGrid.options.pageSize > 0)
					p += 1;
				toQuery(null, p);
			}
			function toNext() {
				var p = parseInt(defGrid.options.total / defGrid.options.pageSize);
				if (defGrid.options.total % defGrid.options.pageSize > 0)
					p += 1;
				if (defGrid.options.page == p)
					return;
				toQuery(null, defGrid.options.page + 1);
			}
			function toPrev() {
				if (defGrid.options.page == 1)
					return;
				toQuery(null, defGrid.options.page - 1);
			}
			//新增用户弹出窗口
			var addDialog;
			//var index=1;
			function openUserDef() {
				
				//index++;
		    // parent.f_addTab('partner_add'+index+'','新增公司单位','./sysmgt/partner_add.html');
		            
				toReset('#new_user_def input,select,textarea');
				//var region,org,type,trade,lecel,bank
				
				region.setValue('');
				org.setValue('');
// 				typeC.setValue('');
				trade.setValue('');
// 				lecel.setValue('');
				bank.setValue('');
				
				addDialog = $.ligerDialog.open({
					target:$("#new_user_def"),
					title:"新增往来单位",
					width:850,
					height:550
				});
			}
			//密码修改窗口
			function open_Modfiy_PW(rowid) {
	        	userid = defGrid.getRow(rowid)['id'];;
	        	if (userid) {
		        	toReset('#up_dict_pw input,select,textarea');
					addDialog = $.ligerDialog.open({
						target:$("#up_dict_pw"),
						title:"密码修改",
						width:350,
						height:370
					});
	        	}
			}
			
			// 新增保存处理
			function toAdd() {
				var valid = true;
				$('*[id$="S"],*[id$="_combobox"]').each(function(index, element) {
					if (!$(this).rules()) return;
					if (!$(element).valid()) {
						valid = false;
						return;
					}
				});
				if (!valid) return;
				var param = new Object();
				param.code=$("#codeS").val();
				param.name = $("#newNameS").val();
				param.type = $("#newType").val();
				param.Of_Region= $("#Of_Region").val();
				param.uuid_code=$("#newuuid_code").val();
				param.tax_code = $("#newTax_code").val();
				param.of_trade=$("#newOf_trade").val();
				param.legal_body=$("#newLegal_body").val();
				param.credit_level=$("#newCredit_level").val();
				param.bank=$("#newBank").val();
				param.bank_account=$("#newBank_account").val();
				param.link_man=$("#newLink_man").val();
				param.mobile=$("#newMobile").val();
				param.phone=$("#newPhone").val();
				param.fax=$("#newFax").val();
				param.description=$("#newDesc").val();
				param.companyid='0001';
				param.deptid=$("#Dept_ID").val();
				param.busiorgid='0001';
				param.ofregion='0001';
				var data = JSON.stringify(reqObj('a','rbac.add.dict.def.addPartner',JSON.stringify(param)));
				ajaxSubmit("/cmwifi/rbac/cm.do?m=a", data, function(data) {
					if (data) {
						//alert(parseInt(data['status']));
						if (parseInt(data['status']) > 0) {
							$.ligerDialog.success('保存成功', '操作完成', function() {
							addDialog.hide();
							toQuery();
						});
						}  else {
							$.ligerDialog.error('保存失败');
						}
					}
				});
			}
			
		   function toModify(row) {
				
				 var param = JSON.stringify(reqObj('u','rbac.update.dict.def.updatepartner',row));
					//alert(param);
					ajaxSubmit("/cmwifi/rbac/cm.do?m=u", param, function(data) {
						if (data) {
							if (parseInt(data['status']) > 0) {
								$.ligerDialog.success('保存成功');
							} else {
								$.ligerDialog.error('保存失败');
							}
						}
					});
			}
		   //删除时，判断此用户下是否已设置角色信息，删除时提示，将删除用户的角色设置信息
		   //确认删除时，将用户下的角色设置信息一并删除。
			function toDel(row) {
				 var param = JSON.stringify(reqObj('d','rbac.delete.dict.def.deletepartner',row));
					ajaxSubmit("/cmwifi/rbac/cm.do?m=d", param, function(data) {
						if (data) {
							if (parseInt(data['status']) > 0) {
								$.ligerDialog.success('删除成功');
							} else {
								$.ligerDialog.error('删除失败');
							}
						}
					});
			}
                
			
	    </script>
		<style type="text/css">
			label{margin: 5px 20px 5px 15px;}
			.fields{height:35px;padding-top:5px;}
			.dict-info{width: 260px;padding: 10px;}
			.diff {margin:3px 0;}
			.lineD {width:99%;float:left;position:relative;overflow:hidden;margin:10px 0 2px 2px}
			.labelD {width:26%;position:relative;float:left;padding-top:3px;}
			.dplD {width:73%;position:relative;float:left;}
			.title{font-size:14px;font-weight:bold;background-position:left;padding-left:18px;}
		</style>
	</head>
	<body style="padding:0;">
		<div id="pageloading"></div>  
		<div id="layout_main">
			<div position="center" id="a_center" title="用户列表">
				<div id="query_cond" class="fields">
					<label>名称</label><input type="text" class="s-text txt-def" id="PartnerName" />
					<label>编号</label><input type="text" class="s-text txt-def" id="PartnerCode" />
					<input type="button" value="查询" style="margin-left:25px;" onclick="toQuery();" />
					<input type="button" value="清空" onclick="toReset('#query_cond input,select,textarea');" />
				</div>
				<div id="query_list"></div>
			</div>
		</div>
		<div id="new_user_def" style="display:none;overflow:hidden;">
			
			<form name="basic-form" method="post" id="basic_form" class="liger-form" data-validate="{}">
			<div class="line-div" style="margin-bottom:10px;">
                <span class="title l-icon-add">添加往来单位</span>
            </div>
				<div class="line-div">
					<div class="label-div"><label>编号</label></div>
					<div class="in-div"><input type="text" class="required s-text txt-def" id="codeS" /></div>
					<div class="label-div"><label>名称</label></div>
					<div class="in-div"><input type="text" class="required s-text txt-def" id="newNameS" /></div>
				</div>
				<div class="line-div">
					<div class="label-div"><label>所属机构</label></div>
					<div class="in-div"><input type="text" id="org_combobox" ltype="combobox" class="required txt-def"/></div>
					<input type="hidden" id="Dept_ID" />
					
					<div class="label-div"><label>所属行政区划</label></div>
					 
					<div class="in-div"><input type="text" id="region_combobox" ltype="combobox" class="required" validate="{required:true,minlength:3,maxlength:10,notnull:true}" nullText="不能为空!"/></div>
					<input type="hidden" id="Of_Region" />
				</div>	
				<div class="line-div">
					<div class="label-div"><label>组织机构代码证号</label></div>
					<div class="in-div"><input type="text" class="required s-text txt-def" id="newuuid_code" /></div>
				
					<div class="label-div"><label>税号</label></div>
					<div class="in-div"><input type="text" class="required s-text txt-def" id="newTax_code" /></div>
				</div>
				<div class="line-div">
					<div class="label-div"><label>所属行业</label></div>
				    <div class="in-div"><input type="text" id="trade_combobox" ltype="combobox" class="required" validate="{required:true,minlength:3,maxlength:10,notnull:true}" nullText="不能为空!"/></div>
					<input type="hidden" id="newOf_trade" />
				
					<div class="label-div"><label>法人代表</label></div>
					<div class="in-div"><input type="text" class="required s-text txt-def" id="newLegal_body" /></div>
				</div>
				<div class="line-div">
					<!--  <div class="label-div"><label>信用级别</label></div>
				    <div class="in-div"><input type="text" id="lecel_combobox" ltype="combobox" class="diff" validate="{required:true,minlength:3,maxlength:10,notnull:true}" nullText="不能为空!"/></div>
					<input type="hidden" id="newCredit_level" />
				-->
					<div class="label-div"><label>开户行</label></div>
				    <div class="in-div"><input type="text" id="bank_combobox" ltype="combobox" class="" validate="{required:true,minlength:3,maxlength:10,notnull:true}" nullText="不能为空!"/></div>
					<input type="hidden" id="newBank" />
					
					<div class="label-div"><label>银行帐号</label></div>
					  <div class="in-div"><input type="text" class="s-text txt-def" id="newBank_account" /></div>
				
				</div>
				<div class="line-div">
					
					<div class="label-div"><label>联系人</label></div>
					<div class="in-div"><input type="text" class="s-text txt-def" id="newLink_man" /></div>
					
					<div class="label-div"><label>手机号</label></div>
					<div class="in-div"><input type="text" class="s-text txt-def" id="newMobile" /></div>
				
				</div>
				<div class="line-div">
					
					<div class="label-div"><label>单位电话</label></div>
					<div class="in-div"><input type="text" class="s-text txt-def" id="newPhone" /></div>
					
					<div class="label-div"><label>单位传真</label></div>
					<div class="in-div"><input type="text" class="s-text txt-def" id="newFax" /></div>
				
				</div>
				<div class="line-div">
					<div class="label-div"><label>说明</label></div>
					<div class="in-div"><textarea cols="80" rows="5" id="newDesc"></textarea></div>
				</div>
			</form>
			<div class="line-div" style="margin-top:95px;padding-left:40%;">
				<input type="button" value="保存" onclick="toAdd();" />
				<input type="button" value="清空" onclick="toReset('#new_user_def input,select,textarea')" />
			</div>
		</div>
		
		
	</body>
</html>